<script setup>
  // import { sysLogin } from '@/api/login'
  import { ref } from 'vue'
  import { User, Lock } from '@element-plus/icons-vue'
  import router from '@/router'
  import { ElMessage } from 'element-plus'
  import { login } from '@/api/login'
  const form = ref({
    username: 'admin',
    password: '123456'
  })
  const rules = ref({
    username: [{ required: true, message: '请输入账号', trigger: 'change' }],
    password: [{ required: true, message: '请输入密码', trigger: 'change' }]
  })
  const submit = async () => {
    console.log(form.value)
    const result = await login(form.value)
    if (result.code === 200) {
      ElMessage.success('登录成功')
      router.push('/home/category')
    } else {
      ElMessage.error('账号或密码错误')
    }
  }
</script>

<template>
  <div class="login-page">
    <el-card class="login-card">
      <div class="form">
        <el-form :model="form" :rules="rules">
          <el-form-item label="账号" prop="username">
            <el-input v-model="form.username" placeholder="请输入账号" :prefix-icon="User" />
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input
              v-model="form.password"
              type="password"
              show-password
              placeholder="请输入密码"
              :prefix-icon="Lock"
            />
          </el-form-item>
        </el-form>
      </div>
      <div class="footer">
        <el-button type="primary" class="btn" @click="submit">登录</el-button>
      </div>
    </el-card>
  </div>
</template>

<style scoped lang="scss">
  .login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    .login-card {
      width: 600px;
      height: 400px;
      display: flex;
      justify-content: center;
      align-items: center;
      .form {
        :deep(.el-input__inner) {
          height: 40px;
          width: 300px;
        }
      }
      .footer {
        margin-top: 40px;
        text-align: center;
        .btn {
          width: 150px;
          height: 50px;
          font-size: 18px;
        }
      }
    }
  }
</style>
